import { createRouter, createWebHistory } from 'vue-router'
import CustomerLoginView from '../views/CustomerLogin.vue'
import HomeShopView from '../views/HomeShop.vue'
import SellerLogin from '@/views/SellerLogin.vue'
import SellerLayout from '@/views/SellerLayout.vue'
import SellerProductManage from '@/views/SellerProductManage.vue'
import SalesAnalytics from '@/views/SalesAnalytics.vue'
import SellerCategoryManage from '@/views/SellerCategoryManage.vue'
import SellerOrderManage from '@/views/SellerOrderManage.vue'
import SellerInfo from '@/views/SellerInfo.vue'
import PaymentResult from '@/views/PaymentResult.vue'

import UserInfoView from '../views/UserInfo.vue'
import ProductDetailView from '../views/ProductDetail.vue'
import OrderDetailView from '../views/OrderDetail.vue'
import CustomerOrderManage from '../views/CustomerOrderManage.vue'
import BecomeSeller from '../views/BecomeSeller.vue'
import CartView from '../views/CartView.vue'
import MainLayout from '../layouts/MainLayout.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'homeShop',
      component: MainLayout,
      children: [
        {
          path: '',
          component: HomeShopView
        },
        {
          path: 'product/:id',
          name: 'productDetail',
          component: ProductDetailView
        },
        {
          path: 'order/:orderId',
          name: 'orderDetail',
          component: OrderDetailView
        },
        {
          path: 'cart',
          name: 'cart',
          component: CartView
        },
        {
          path: 'ai-chat',
          name: 'aiChat',
          // 懒加载优化路由性能
          component: () => import('../views/AiChatView.vue')
        }
      ]
    },
    {
      path: '/about',
      name: 'about',
      component: MainLayout,
      children: [
        {
          path: '',
          // route level code-splitting
          // this generates a separate chunk (About.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import('../views/AboutView.vue')
        }
      ]
    },
    {
      path: '/payment/result',
      name: 'paymentResult',
      component: MainLayout,
      children: [
        {
          path: '',
          component: PaymentResult
        }
      ]
    },
    {
      path: '/customer-login',
      name: 'customerLogin',
      component: CustomerLoginView,
    },
    {
      path: '/user-info',
      name: 'userInfo',
      component: MainLayout,
      children: [
        {
          path: '',
          component: UserInfoView
        }
      ]
    },
    {
      path: '/customer-orders',
      name: 'customerOrders',
      component: MainLayout,
      children: [
        {
          path: '',
          component: CustomerOrderManage
        }
      ]
    },
    {
      path: '/become-seller',
      name: 'becomeSeller',
      component: MainLayout,
      children: [
        {
          path: '',
          component: BecomeSeller
        }
      ]
    },
   {
      path: '/seller-login',
      name: 'sellerLogin',
      component: SellerLogin,
    },
    // 商家后台布局路由
    {
      path: '/seller',
      name: 'sellerLayout',
      component: SellerLayout,
      children: [
        {
          path: 'product-manage',
          name: 'sellerProductManage',
          component: SellerProductManage,
        },
        {
          path: 'category-manage',
          name: 'sellerCategoryManage',
          component: SellerCategoryManage,
        },
        {
          path: 'analytics',
          name: 'salesAnalytics',
          component: SalesAnalytics,
        },
        {
          path: 'order-manage',
          name: 'sellerOrderManage',
          component: SellerOrderManage,
        },
        {
          path: 'info',
          name: 'sellerInfo',
          component: SellerInfo,
        },
        // 默认重定向到商品管理
        {
          path: '',
          redirect: 'product-manage'
        }
      ]
    },
    // 保持旧路由的兼容性（重定向到新路由）
    {
      path: '/seller-product-manage',
      redirect: '/seller/product-manage'
    },
    {
      path: '/sales-analytics',
      redirect: '/seller/analytics'
    },
    {
      path: '/seller/:id',
      name: 'seller',
      component: MainLayout,
      children: [
        {
          path: '',
          component: () => import('../views/SellerPage.vue')
        }
      ]
    }
  ]
})


export default router
